<div class="container">

    <div class="page-header">
        <div class="row">
            <h1 class="span8">View All :: <?=ucfirst($_GET['type']);?> gallery</h1>
            <span class="span4 clearfix">
                <a class="nav-control new-page w-18" href="<?=base_url($link.'/view_new?post_type=gallery')?>">
                    Add Gallery
                </a>
            </span>
        </div>


    </div>

    <div class="row">

        <div class="span12">

            <table class="table table-striped table-bordered table-condensed">
                <thead>
                    <tr>
                        <th>Gallery</th>
                        <th>Link to</th>
                        <th>Images</th>
                        <th>Videos</th>
                        <th class="th-action center">Action</th>
                    </tr>
                </thead>
                <tbody>

                    <?  foreach($all_galleries as $pg): ?> 

                        <? if($pg['posts_ID']!=NULL){ $page = $this->translate->trans_row_array($this->pages_model->view_edit($pg['posts_ID'])); }?>

                        <? //print_r($page); ?>

                        <tr>

                            <td><a href="<?=base_url($link.'/view_edit?gallery_ID='.$pg['ID'].'&post_type=gallery')?>"><strong><?=$pg['title']?></strong></a></td>
                            <td><?=$pg['posts_ID']!=NULL  ?  $page['post_title']  :  'Not linked' ?></td>
                            <td><?=$pg['pic_count']?></td>
                            <td><?=$pg['vid_count']?></td>
                            <td class="center">
                                <a href="<?=base_url()?><?=$link?>/view_edit?gallery_ID=<?=$pg['ID']?>&post_type=<?=$post_type?>"><i class="icon-pencil"></i> Edit</a> |
                                <a href="<?=base_url()?><?=$link?>/delete/<?=$pg['ID']?>?post_type=<?=$post_type?>" class="delete_post"><i class="icon-trash"></i> Delete</a>
                            </td> 

                        </tr>    

                        <?

                            $first_child = $this->gallery_model->view_all_children($pg['ID']);

                            if(count($first_child)>0):

                                foreach($first_child as $fc):?>  

                                <? if($fc['posts_ID']!=NULL){ $page = $this->translate->trans_row_array($this->pages_model->view_edit($fc['posts_ID'])); }?>

                                <tr>

                                    <td><a href="<?=base_url($link.'/view_edit?gallery_ID='.$fc['ID'].'&post_type=gallery')?>">-- <?=$fc['title']?></a></td>
                                    <td><?=$fc['posts_ID']!=NULL  ?  $page['post_title']  :  'Not linked' ?></td>
                                    <td><?=$fc['pic_count']?></td>
                                    <td><?=$fc['vid_count']?></td>
                                    <td class="center">
                                        <a href="<?=base_url()?><?=$link?>/view_edit?gallery_ID=<?=$fc['ID']?>&post_type=<?=$post_type?>"><i class="icon-pencil"></i> Edit</a> |
                                        <a href="<?=base_url()?><?=$link?>/delete/<?=$fc['ID']?>?post_type=<?=$post_type?>" class="delete_post"><i class="icon-trash"></i> Delete</a>
                                    </td> 

                                </tr> 

                                <? endforeach; ?> 

                            <? endif; ?>

                        <? endforeach; ?>

                </tbody>
            </table>

        </div>

    </div>

</div> <!-- /container -->

<script type="text/javascript" charset="utf-8">
    jQuery(document).ready(function() {

            jQuery('.delete_post').live('click',function(){

                    var conf = confirm("Delete <?=ucfirst($post_type)?>?")
                    if (!conf){
                        return false;
                    }

                    window.location.href = jQuery(this).attr('href');

                    return false;

            });

    } );
</script>